//
//  HYAddOrSaveDeviceApi.m
//  TJHYHardwareProduct
//
//  Created by JianWei Chen on 2018/1/23.
//  Copyright © 2018年 Kendama. All rights reserved.
//

#import "HYAddOrSaveDeviceApi.h"

@implementation HYAddOrSaveDeviceApi{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/device/save_device";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    NSMutableDictionary *dic = [NSMutableDictionary getPubdic];
    
    [dic setValuesForKeysWithDictionary:_dic];
    NSString *sign=[NSString getSign:dic];
    [dic setObject:sign forKey:@"sign"];
    return dic;
}


-(void)dealloc
{
    NSLog(@"%@ dealloc",[self class]);
}

+ (void)addDevice:(NSString *)device_type dno:(NSString *)dno province:(NSString *)province city:(NSString *)city district:(NSString *)district cid:(NSString *)cid child_cid:(NSString *)child_cid dong:(NSString *)dong ceng:(NSString *)ceng fang:(NSString *)fang lose_connection_time:(NSString *)lose_connection_time is_ignore:(NSString *)is_ignore success:(void (^)(NSDictionary *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:device_type forKey:@"device_type"];
    [requestDic setValue:dno forKey:@"dno"];
    [requestDic setValue:province forKey:@"province"];
    [requestDic setValue:city forKey:@"city"];
    [requestDic setValue:district forKey:@"district"];
    [requestDic setValue:cid forKey:@"cid"];
    if (![child_cid isEqualToString:@"0"])
    {
        [requestDic setValue:child_cid forKey:@"child_cid"];
    }
    [requestDic setValue:dong forKey:@"dong"];
    [requestDic setValue:ceng forKey:@"ceng"];
    [requestDic setValue:fang forKey:@"fang"];
    [requestDic setValue:lose_connection_time forKey:@"lose_connection_time"];
    [requestDic setValue:is_ignore forKey:@"is_ignore"];
    
    HYAddOrSaveDeviceApi *api = [[HYAddOrSaveDeviceApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        if (successBack) {
            successBack(request.responseObject);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}

+ (void)saveDevice:(NSString *)deviceId device_type:(NSString *)device_type dno:(NSString *)dno province:(NSString *)province city:(NSString *)city district:(NSString *)district cid:(NSString *)cid child_cid:(NSString *)child_cid dong:(NSString *)dong ceng:(NSString *)ceng fang:(NSString *)fang lose_connection_time:(NSString *)lose_connection_time is_ignore:(NSString *)is_ignore success:(void (^)(NSDictionary *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:device_type forKey:@"device_type"];
    [requestDic setValue:dno forKey:@"dno"];
    [requestDic setValue:province forKey:@"province"];
    [requestDic setValue:city forKey:@"city"];
    [requestDic setValue:district forKey:@"district"];
    [requestDic setValue:cid forKey:@"cid"];
    if (![child_cid isEqualToString:@"0"])
    {
        [requestDic setValue:child_cid forKey:@"child_cid"];
    }
    [requestDic setValue:dong forKey:@"dong"];
    [requestDic setValue:ceng forKey:@"ceng"];
    [requestDic setValue:fang forKey:@"fang"];
    [requestDic setValue:lose_connection_time forKey:@"lose_connection_time"];
    [requestDic setValue:is_ignore forKey:@"is_ignore"];
    if (deviceId)
    {
        [requestDic setValue:deviceId forKey:@"id"];
    }
    
    HYAddOrSaveDeviceApi *api = [[HYAddOrSaveDeviceApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        if (successBack) {
            successBack(request.responseObject);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}


+ (void)addDevice:(NSString *)device_type dno:(NSString *)dno cid:(NSString *)cid child_cid:(NSString *)child_cid dong:(NSString *)dong ceng:(NSString *)ceng fang:(NSString *)fang lose_connection_time:(NSString *)lose_connection_time is_ignore:(NSString *)is_ignore success:(void (^)(NSDictionary *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:device_type forKey:@"device_type"];
    [requestDic setValue:dno forKey:@"dno"];
    [requestDic setValue:cid forKey:@"cid"];
    if (![child_cid isEqualToString:@"0"])
    {
        [requestDic setValue:child_cid forKey:@"child_cid"];
    }
    [requestDic setValue:dong forKey:@"dong"];
    [requestDic setValue:ceng forKey:@"ceng"];
    [requestDic setValue:fang forKey:@"fang"];
    [requestDic setValue:lose_connection_time forKey:@"lose_connection_time"];
    [requestDic setValue:is_ignore forKey:@"is_ignore"];
    
    HYAddOrSaveDeviceApi *api = [[HYAddOrSaveDeviceApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        if (successBack) {
            successBack(request.responseObject);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}

+ (void)saveDevice:(NSString *)deviceId device_type:(NSString *)device_type dno:(NSString *)dno cid:(NSString *)cid child_cid:(NSString *)child_cid dong:(NSString *)dong ceng:(NSString *)ceng fang:(NSString *)fang lose_connection_time:(NSString *)lose_connection_time is_ignore:(NSString *)is_ignore success:(void (^)(NSDictionary *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:device_type forKey:@"device_type"];
    [requestDic setValue:dno forKey:@"dno"];
    [requestDic setValue:cid forKey:@"cid"];
    if (![child_cid isEqualToString:@"0"])
    {
        [requestDic setValue:child_cid forKey:@"child_cid"];
    }
    [requestDic setValue:dong forKey:@"dong"];
    [requestDic setValue:ceng forKey:@"ceng"];
    [requestDic setValue:fang forKey:@"fang"];
    [requestDic setValue:lose_connection_time forKey:@"lose_connection_time"];
    [requestDic setValue:is_ignore forKey:@"is_ignore"];
    if (deviceId)
    {
        [requestDic setValue:deviceId forKey:@"id"];
    }
    
    HYAddOrSaveDeviceApi *api = [[HYAddOrSaveDeviceApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        if (successBack) {
            successBack(request.responseObject);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}
@end
